package cn.kgc.rui;

import org.apache.hadoop.util.QuickSort;

import java.lang.reflect.Array;
import java.util.Arrays;

public class KuaiPai {
    public static void main(String[] args) {
        int[] arr = {5,43,21,7,8};
        Quick_Sort(arr,0,arr.length-1);
        System.out.println(Arrays.toString(arr));
    }
     static void Quick_Sort(int[] arr, int begin, int end){
        if(begin > end)
            return;
        int tmp = arr[begin];
        int i = begin;
        int j = end;
        while(i != j){
            while(arr[j] >= tmp && j > i)
                j--;
            while(arr[i] <= tmp && j > i)
                i++;
            if(j > i){
                int t = arr[i];
                arr[i] = arr[j];
                arr[j] = t;
            }
        }
        arr[begin] = arr[i];
        arr[i] = tmp;
        Quick_Sort(arr, begin, i-1);
        Quick_Sort(arr, i+1, end);
    }

}
